package cn.element.io.bio.case2;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;

public class Client {

    public static void main(String[] args) {
        try {
            // 1.创建一个Socket对象请求服务器的连接
            Socket socket = new Socket("127.0.0.1", 8848);

            // 2.从Socket对象中获取一个字节输出流
            OutputStream os = socket.getOutputStream();

            // 3.把字节输出流包装成一个打印流
            PrintStream ps = new PrintStream(os);
            Scanner scanner = new Scanner(System.in);

            while (true) {
                System.out.println("请说: ");
                String msg = scanner.nextLine();
                ps.println(msg);
                ps.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
